package com.sc.dao.impl;

import com.sc.dao.CartDao;
import com.sc.entity.Cart;
import com.sc.utils.JDBCUtils;

import java.util.List;

public class CartDaoImpl implements CartDao {

    @Override
    public int add(Cart cart) throws Exception {
        String sql = "insert into cart (user_id) values (?)";
        return JDBCUtils.update(sql, new Object[]{cart.getUserId()});
    }

    @Override
    public int delete(int id) throws Exception {
        String sql = "delete from cart where id = ?";

        return JDBCUtils.update(sql,new Object[]{id});
    }

    @Override
    public int update(Cart cart) throws Exception {
      String sql = "update cart set user_id = ?";
      return JDBCUtils.update(sql,new Object[]{cart.getUserId()});

    }

    @Override
    public Cart queryById(int id) throws Exception {
        String sql = "select from cart where id = ?";
        return JDBCUtils.query(sql, Cart.class,new Object[]{id});

    }

    @Override
    public List<Cart> queryAll() throws Exception {
      String sql = "select from cart ";
      return JDBCUtils.querylist(sql, Cart.class,new Object[]{0});
    }
    @Override
    public Cart findByIdAndStatusEq0(int user_id) throws Exception {
        String sql = "select * from cart where status = 0 and id = ?";
        return (Cart) JDBCUtils.query(sql, Cart.class, new Object[]{user_id});
    }

    @Override
    public Cart findByUserId(Integer user_Id) throws Exception {
        String sql="select*from cart where user_id =?";
        return (Cart) JDBCUtils.query(sql,Cart.class,new Object[]{user_Id});
    }

}
